/**   
 * @Title: GovDealListPortletController.java 
 * @Package org.ezplatform.goa.document.web.rest 
 * @Description: 
 * @author xuwl
 * @date 2019-11-21 2:23:14 PM 
 */
package org.ezplatform.goa.document.web.rest;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;

import javax.servlet.http.HttpServletRequest;

import org.ezplatform.cloud.api.bpm.BpmApiService;
import org.ezplatform.cloud.common.client.RestClient;
import org.ezplatform.core.common.WebUser;
import org.ezplatform.core.exception.ValidationException;
import org.ezplatform.core.web.util.WebUtils;
import org.ezplatform.core.web.view.OperationResult;
import org.ezplatform.goa.document.entity.DocSignreport;
import org.ezplatform.goa.document.entity.GovDocReceiveFile;
import org.ezplatform.goa.document.entity.GovSendFile;
import org.ezplatform.goa.document.service.DocSignreportService;
import org.ezplatform.goa.document.service.GovDealListPortalService;
import org.ezplatform.goa.document.service.GovDistributeRecordService;
import org.ezplatform.goa.document.service.GovDistributeUserService;
import org.ezplatform.goa.document.service.GovDocReceiveFileService;
import org.ezplatform.goa.document.service.GovFlowBackService;
import org.ezplatform.goa.document.service.GovMyAttentionService;
import org.ezplatform.goa.document.service.GovRegisterService;
import org.ezplatform.goa.document.service.GovSendFileService;
import org.ezplatform.goa.document.util.DocumentSecUtils;
import org.ezplatform.goa.document.util.DocumentValidateUtil;
import org.ezplatform.office.portlet.common.web.controller.PortletBaseController;
import org.ezplatform.util.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.google.common.collect.Lists;
import com.itextpdf.text.log.SysoLogger;

/**
 * 公文办理列表门户controller
 * 
 * @ClassName: GovDealListPortletController
 * @author xuwl
 * @date 2019-11-21 2:23:14 PM
 */
@Controller
@RequestMapping(value = "/api/w/portlet/portalpage/goadeallist")
public class GovDealListPortletController extends PortletBaseController {
	
	private final Logger logger = LoggerFactory.getLogger(GovDealListPortletController.class);
	
	@Autowired
	private GovDistributeUserService disService;
	
	@Autowired
	private GovDistributeRecordService govDistributeRecordService;
	
	@Autowired
	private GovFlowBackService govFlowBackService;

	@Autowired
	private DocumentSecUtils documentSecUtils;

	@Autowired
	private GovSendFileService sendFileService;

	@Autowired
	private GovDocReceiveFileService receiveFileService;
	
	@Autowired
	private DocSignreportService signReportService;
	
	@Autowired
	public GovMyAttentionService myAttentionService;
	
	@Autowired
    private GovRegisterService goaDocRegisterService;
	
	@Autowired
	private RestClient restClient;

	@Autowired
	private GovDealListPortalService govDealListPortalService;

    @Autowired
    private BpmApiService bpmApiService;
	
	private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

	public GovDealListPortletController() {
		this.CODE = "goadeallist";
		this.MODULE = "portalpage";
	}

	/**
	 * 公文列表门户
	 * @name: show
	 * @param request
	 * @param portalKey 门户key
	 * @return: org.ezplatform.core.web.view.OperationResult
	 * @date: 2022/10/17 15:15
	 *
	*/
	@SuppressWarnings("all")
	@RequestMapping(value = "/show", method = RequestMethod.GET)
	@ResponseBody
	public OperationResult show(HttpServletRequest request,
			@RequestParam(value = "portalKey", required = true) String portalKey) throws InterruptedException, ExecutionException {
        if (!DocumentValidateUtil.validateParamsString(portalKey)) {
            throw new ValidationException("非法参数");
        }
		Map personalConfig = portletService.preparePersonalData(portalKey);
		Map baseConfig = portletService.prepareBaseData(portalKey);
		personalConfig.putAll(baseConfig);
		Map paramMap = new HashMap();
		String showNumber = "5";
		String showDateFormat = StringUtils.null2String(personalConfig.get("showDateFormat"));
		String showItemSet = StringUtils.null2String(personalConfig.get("showItemSet"));
		if ((personalConfig.get("showNumber") != null)
				&& (StringUtils.isNotBlank(personalConfig.get("showNumber").toString()))) {
			showNumber = personalConfig.get("showNumber").toString();
			paramMap.put("showNumber", StringUtils.isEmpty(showNumber) ? "5" : showNumber);
		} else {
			paramMap.put("showNumber", showNumber);
		}
		Map data = new HashMap();
		data.put("settings", personalConfig);
		if ((("1".equals(personalConfig.get("showItemType")) || ("3".equals(personalConfig.get("showItemType")))) && StringUtils.isNotBlank(personalConfig.get("showItemTab").toString()))
				|| ("2".equals(personalConfig.get("showItemType")) && StringUtils.isNotBlank(personalConfig.get("showItemTab2").toString()))) {
			if("1".equals(personalConfig.get("showItemType")) || "3".equals(personalConfig.get("showItemType"))) {
				// 固定显示
				String[] split = personalConfig.get("showItemTab").toString().split(",");
				List listMap = new ArrayList();
				WebUser user = WebUtils.getCurrentUser();
				Long start = System.currentTimeMillis();
				Long end = System.currentTimeMillis();
				//logger.info("办理时间："+(end-start));
				String currentModule = "";
				if("0".equals(split[0])) {
					currentModule = "0";
					currentModule = String.valueOf(personalConfig.get("showItemTab")).indexOf("1")>-1 ? currentModule + ",1" : currentModule;
				}else {
					currentModule = split[0];
					currentModule = String.valueOf(personalConfig.get("showItemTab")).indexOf("0")>-1 && currentModule.indexOf("0")==-1? currentModule + ",0" : currentModule;
					currentModule = String.valueOf(personalConfig.get("showItemTab")).indexOf("1")>-1 && currentModule.indexOf("1")==-1 ? currentModule + ",1" : currentModule;
				}
				listMap = govDealListPortalService.getProcessList(split, showNumber, showDateFormat, showItemSet, user,currentModule);
//				listMap = documentSecUtils.documentListEncodeListById(listMap);
//				listMap = DocumentSecUtils.approveListEncodeList(listMap,"processInstanceId","");
				Long end1 = System.currentTimeMillis();
				//logger.info("办理时间："+(end1-start));
				data.put("listMap", listMap);
			}else {
				// 切换显示
				/*String[] split = personalConfig.get("showItemTab2").toString().split(",");
				List listMap = new ArrayList();
				WebUser user = WebUtils.getCurrentUser();
				listMap = govDealListPortalService.getProcessDataList(split, showNumber, showDateFormat, showItemSet, user,split[0]);
				data.put("listMap", listMap);*/
			}
		} else {
			data.put("listMap", null);
		}
		return OperationResult.buildSuccessResult(data);
	}


	

	/**
	 * 获取页签列表数据
	 * @name: getGovDealList
	 * @param request
	 * @param module 模块
	 * @param showNumber 显示条数
	 * @param showDateFormat 日期格式
	 * @param showItemSet 显示项
	 * @return: org.ezplatform.core.web.view.OperationResult
	 * @date: 2022/10/17 15:16
	 *
	*/
	@RequestMapping(value = "/getGovDealList", method = RequestMethod.GET)
	@ResponseBody
	public OperationResult getGovDealList(HttpServletRequest request) throws InterruptedException, ExecutionException{
		WebUser user = WebUtils.getCurrentUser();
		// 当前页签模块编码
		String module = ValidateUtils.filter(StringUtils.null2String(request.getParameter("module")));
		String[] split = module.split(",");
		// 显示数量
		String showNumber = ValidateUtils.filter(StringUtils.null2String(request.getParameter("showNumber")));
		// 日期格式
		String showDateFormat = ValidateUtils.filter(StringUtils.null2String(request.getParameter("showDateFormat")));
		String showItemSet = ValidateUtils.filter(StringUtils.null2String(request.getParameter("showItemSet")));
//        if (!DocumentValidateUtil.validateParamsString(module,showNumber,showDateFormat,showItemSet)) {
//        if (!DocumentValidateUtil.validateParamsString(module,showNumber,showItemSet)) {
//            throw new ValidationException("非法参数");
//        }
		List<Map> listInfoMap = govDealListPortalService.getProcessList(split, showNumber, showDateFormat, showItemSet,user, module);
//		listInfoMap = documentSecUtils.documentListEncodeListById(listInfoMap);
		Map data = new HashMap();
		data.put("listInfoMap", listInfoMap);
		return OperationResult.buildSuccessResult(data);
	}
	
	/**
	 * 获取门户配置
	 * @name: getConfigData
	 * @param request
	 * @param portalKey 门户key
	 * @return: org.ezplatform.core.web.view.OperationResult
	 * @date: 2022/10/17 15:17
	 *
	*/
	@RequestMapping(value = "/getConfigData", method = RequestMethod.GET)
	@ResponseBody
	public OperationResult getConfigData(HttpServletRequest request,
			@RequestParam(value = "portalKey", required = true) String portalKey) {
        if (!DocumentValidateUtil.validateParamsString(portalKey)) {
            throw new ValidationException("非法参数");
        }
		Map<String, Object> personalConfig = portletService.preparePersonalData(portalKey);
		Map<String, Object> data = new HashMap<String, Object>();
		data.put("settings", personalConfig);
		return OperationResult.buildSuccessResult(data);

	}
	
	@SuppressWarnings("all")
	private Map<String, Object> getProcessDataList(String module, String limit, String showDateFormat, String showItemSet) {
		WebUser user = WebUtils.getCurrentUser();
		int limitSize = Integer.parseInt(limit);
		Map map = new HashMap();
		map.put("module", module);
		String moduleName = "";
		List<Map> list = new ArrayList<>();
		List todayList = new ArrayList<>();
		List yesterdayList = new ArrayList<>();
		List thisWeekList = new ArrayList<>();
		List moreList = new ArrayList<>();
		String category = "";
		String typeSearch = "";
		switch (module) {
			case "0":
				moduleName = "待办发文";
				category = "goa_doc_sendfile";
				break;
			case "1":
				moduleName = "待办收文";
				category = "goa_doc_receivefile";
				break;
			case "2":
				moduleName = "待办签报";
				category = "goa_doc_signreport";
				break;
			case "3":
				moduleName = "待阅正式公文";
				typeSearch = "1";
				break;
			case "4":
				moduleName = "待阅发文";
				typeSearch = "2";
				break;
			case "5":
				moduleName = "待阅收文";
				typeSearch = "3";
				break;
			case "6":
				moduleName = "待阅签报";
				typeSearch = "4";
				break;
			case "7":
				moduleName = "登记未处理";
				break;
		}
		if("0".equals(module) || "1".equals(module) || "2".equals(module)) {
			// 待办
			Map userParams = new HashMap();
			userParams.put("userId", user.getUserId());
			userParams.put("corpId", user.getCorpId());
			userParams.put("index", "0");
			userParams.put("limit", limitSize);
			userParams.put("category", category);
			userParams.put("module", "goa_document");
			userParams.put("from", "pendingList");
			userParams.put("groupId", user.getCurrentPtOrgId());
			String json = bpmApiService.getUndoTaskList(userParams,user.getJwtToken());
			Map jsonMap = JsonUtils.readValue(json);
			Map data = (Map) jsonMap.get("data");
			list = (List) data.get("list");
			for (Map m : list) {
				// 今天或昨天
				if(isToday(m.get("createTime")+"")) {
					todayList.add(m);
				}else if(isYesterday(m.get("createTime")+"")) {
					yesterdayList.add(m);
				}
				
				// 非本周即更多
				if(isThisWeek(m.get("createTime")+"")) {
					thisWeekList.add(m);
				}else {
					moreList.add(m);
				}
				String createTime = StringUtils.null2String(m.get("createTime"));
				if (StringUtils.isNotEmpty(createTime)) {
					createTime = DateUtils.formatDate(DateUtils.parseDate(createTime, "yyyy-MM-dd HH:mm:ss"), showDateFormat);
					m.put("createTime", createTime);
				}
				setLightType(m,"0");
			}
		}else if("3".equals(module) || "4".equals(module) || "5".equals(module) || "6".equals(module)) {
			// 待阅
			list = disService.getListByPortlet(typeSearch);

			for (Map m : list) {
				// 今天或昨天
				if(isToday(m.get("createddate")+"")) {
					todayList.add(m);
				}else if(isYesterday(m.get("createddate")+"")) {
					yesterdayList.add(m);
				}
				
				// 非本周即更多
				if(isThisWeek(m.get("createddate")+"")) {
					thisWeekList.add(m);
				}else {
					moreList.add(m);
				}
				String createTime = StringUtils.null2String(m.get("createddate"));
				if (StringUtils.isNotEmpty(createTime)) {
					createTime = DateUtils.formatDate(DateUtils.parseDate(createTime, "yyyy-MM-dd HH:mm:ss"), showDateFormat);
					m.put("createddate", createTime);
				}
			}
		}else {
			// 登记待处理
			list = goaDocRegisterService.getListByPortlet();
			for (Map m : list) {
				// 今天或昨天
				if(isToday(m.get("createTime")+"")) {
					todayList.add(m);
				}else if(isYesterday(m.get("createTime")+"")) {
					yesterdayList.add(m);
				}
				
				// 非本周即更多
				if(isThisWeek(m.get("createTime")+"")) {
					thisWeekList.add(m);
				}else {
					moreList.add(m);
				}
				String createTime = StringUtils.null2String(m.get("createTime"));
				if (StringUtils.isNotEmpty(createTime)) {
					createTime = DateUtils.formatDate(DateUtils.parseDate(createTime, "yyyy-MM-dd HH:mm:ss"), showDateFormat);
					m.put("createTime", createTime);
				}
			}
		}
		map.put("moduleName", moduleName);
		map.put("listCount", list.size());
		map.put("todayListCount", todayList.size());
		map.put("yesterdayListCount", yesterdayList.size());
		map.put("thisWeekListCount", thisWeekList.size());
		map.put("moreListCount", moreList.size());
		if(list.size() > limitSize) {
			map.put("list", list.subList(0, limitSize));
		}else {
			map.put("list", list);
		}
		if(todayList.size() > limitSize) {
			map.put("todayList", todayList.subList(0, limitSize));
		}else {
			map.put("todayList", todayList);
		}
		if(yesterdayList.size() > limitSize) {
			map.put("yesterdayList", yesterdayList.subList(0, limitSize));
		}else {
			map.put("yesterdayList", yesterdayList);
		}
		if(thisWeekList.size() > limitSize) {
			map.put("thisWeekList", thisWeekList.subList(0, limitSize));
		}else {
			map.put("thisWeekList", thisWeekList);
		}
		if(moreList.size() > limitSize) {
			map.put("moreList", moreList.subList(0, limitSize));
		}else {
			map.put("moreList", moreList);
		}
		return map;
	}

	@SuppressWarnings("all")
	private Map<String, Object> getProcessList(String module, String limit, String showDateFormat, String showItemSet) {
		Long start = System.currentTimeMillis();
		WebUser user = WebUtils.getCurrentUser();
		String token = user.getJwtToken();
		Map map = new HashMap();
		map.put("module", module);
		String moduleName = "";
		String url = "";
		switch (module) {
			case "0":
				url = "/bpm/runtime/getUndoTaskList";
				moduleName = "待办公文";
				map.put("editType", "edit");
				map.put("menuType", "pending");
				map.put("permissionCode", "pending");
				break;
			case "1":
				url = "";
				moduleName = "待阅公文";
				map.put("editType", "view");
				map.put("menuType", "unread");
				map.put("permissionCode", "pending");
				break;
			case "2":
				url = "/bpm/runtime/getDoneProcessList";
				moduleName = "已办公文";
				map.put("editType", "view");
				map.put("menuType", "done");
				map.put("permissionCode", "done");
				break;
			case "3":
				url = "";
				moduleName = "已阅公文";
				map.put("editType", "view");
				map.put("menuType", "readed");
				map.put("permissionCode", "pending");
				break;
			case "4":
				url = "/bpm/runtime/getMyProcessList";
				moduleName = "我的发起";
				map.put("editType", "view");
				map.put("menuType", "my");
				map.put("permissionCode", "my");
				break;
			case "5":
				url = "";
				moduleName = "我的分发";
				map.put("editType", "view");
				map.put("menuType", "pending");
				map.put("permissionCode", "pending");
				break;
			case "6":
				url = "";
				moduleName = "我的关注";
				map.put("editType", "view");
				map.put("menuType", "query");
				map.put("permissionCode", "pending");
				break;
			case "7":
				url = "";
				moduleName = "我的退回";
				map.put("editType", "view");
				map.put("menuType", "pending");
				map.put("permissionCode", "pending");
				break;
		}
		map.put("moduleName", moduleName);
		Map paramMap = new HashMap();
		paramMap.put("limit", limit);
		paramMap.put("index", "0");
		paramMap.put("module", "goa_document");
		paramMap.put("from", "govdoc");
		Map result = new HashMap();
		//使用线程的方式改造
		if("1".equals(module)) {
			result = govDealListPortalService.getListByPortlet("0", "unread",limit);
			Long end1 = System.currentTimeMillis();
			logger.info("待阅列表："+(end1-start));
		}else if("3".equals(module)) {
			result = govDealListPortalService.getListByPortlet("0", "readed",limit);
			Long end2 = System.currentTimeMillis();
			logger.info("已阅列表："+(end2-start));
		}else if("5".equals(module)) {
			result = govDealListPortalService.getDisListByPortlet(limit);
			Long end3 = System.currentTimeMillis();
			logger.info("我的分发列表："+(end3-start));
		}else if("6".equals(module)) {
			result = govDealListPortalService.getMyAttentionListByPortlet(limit);
			Long end4 = System.currentTimeMillis();
			logger.info("我的关注列表："+(end4-start));
		}else if("7".equals(module)) {
			result = govDealListPortalService.getFlowBackListByPortlet(limit);
			Long end5 = System.currentTimeMillis();
			logger.info("我的退回列表："+(end5-start));
		}else {
			//是否涉密开启
	        Boolean secretFlag = GlobalConstant.isUseSecretLevel();
	        String secretLevel = "";
	        if(secretFlag) {
	        	//获取当前登录人的涉密登记
	            secretLevel = String.valueOf(user.getSecretLevel());
	            Map userParams = new HashMap();
	    		userParams.put("secretLevel", secretLevel);
	    		paramMap.put("searchData", JsonUtils.writeValueAsString(userParams));      
	        }
	        String json = "";
			Long end6 = System.currentTimeMillis();
			if("0".equals(module)) {
			    json = bpmApiService.getUndoTaskList(paramMap,token);
				logger.info("待办列表："+(end6-start));
			}else if("2".equals(module)) {
			    json = bpmApiService.getDoneProcessList(paramMap,token);
				logger.info("已办列表："+(end6-start));
			}else if("4".equals(module)) {
			    json = bpmApiService.getMyProcessList(paramMap,token);
				logger.info("我的发起列表："+(end6-start));
			}
			if(StringUtils.isNotBlank(json)){
			    result = JsonUtils.readValue(json);
            }
		}
		if ("0".equals(StringUtils.null2String(result.get("code")))) {
			Map data = (Map) result.get("data");
			List listInfo = new ArrayList<>();
			listInfo = (List) data.get("list");
			if("0".equals(module)) {
				map.put("totalNum", data.get("count"));
			}
			if("1".equals(module)) {
				map.put("totalNum", data.get("totalNum"));
			}
			for (int j = 0; j < listInfo.size(); j++) {
				Map info = (Map) listInfo.get(j);
				String createTime = StringUtils.null2String(info.get("createTime"));
				if (StringUtils.isNotEmpty(createTime)) {
					createTime = DateUtils.formatDate(DateUtils.parseDate(createTime, "yyyy-MM-dd HH:mm:ss"), showDateFormat);
					info.put("createTime", createTime);
				}
				if("0".equals(module)) {
					info.put("curStepName", info.get("name"));
					// 判断文件灯、个人灯
					setLightType(info,module);
				}else if("2".equals(module)) {
					if(info.get("curStepName") == null) {
						info.put("curStepName", "结束");
					}
					info.put("id", info.get("taskId"));
					setLightType(info,module);
				}else if("1".equals(module) || "3".equals(module)) {
					createTime = StringUtils.null2String(info.get("createddate"));
					if("3".equals(module)) {
						createTime = StringUtils.null2String(info.get("finishdate"));
					}else {
						String readStatus = info.get("read_status")+"";
						if("1".equals(readStatus)) {
							info.put("claimTime", readStatus);
						}else {
							info.put("claimTime", null);
						}
					}
					if (StringUtils.isNotEmpty(createTime)) {
						createTime = DateUtils.formatDate(DateUtils.parseDate(createTime, "yyyy-MM-dd HH:mm:ss"), showDateFormat);
					}
					info.put("createTime", createTime);
					info.put("formKey", info.get("form_id"));
					info.put("processInstanceId", info.get("process_instance_id"));
					info.put("businessKey", info.get("business_id"));
					info.put("title", info.get("dis_title"));
					info.put("startUserName", info.get("dis_user_name"));
					info.put("startUserGroupName", info.get("dis_org_name"));
					info.put("curStepName", info.get(""));
				}else if("4".equals(module)) {
					 String id = StringUtils.null2String(info.get("businessKey"));
					 String category = StringUtils.null2String(info.get("category"));
					 if(StringUtils.isNoneBlank(id) && "goa_doc_sendfile".equals(category)) {
						 GovSendFile sendfile = sendFileService.findOne(id);
						 if(sendfile != null) {
							 info.put("flowStatus", sendfile.getFlowStatus());
						 }
					 }else if(StringUtils.isNoneBlank(id) && "goa_doc_receivefile".equals(category)) {
						 GovDocReceiveFile receivefile = receiveFileService.findOne(id);
						 if(receivefile != null) {
							 info.put("flowStatus", receivefile.getFlowStatus());	
						 }
					 }else if(StringUtils.isNoneBlank(id) && "goa_doc_signreport".equals(category)) {
						 DocSignreport signReportFile = signReportService.findOne(id);
						 if(signReportFile != null) {
							 info.put("flowStatus", signReportFile.getFlowStatus());
			             }
					 }
					 if("2".equals(info.get("flowStatus"))) {
						 info.put("curStepName", "结束");
					 }else if("3".equals(info.get("flowStatus"))) {
						 info.put("curStepName", "取消");
					 }else if("4".equals(info.get("flowStatus"))) {
						 info.put("curStepName", "作废");
					 }else if("5".equals(info.get("flowStatus"))) {
						 info.put("curStepName", "退回");
					 }
					 info.put("startUserGroupName", user.getOrgName());
					 setLightType(info,module);
				}else if("5".equals(module)) {
					createTime = StringUtils.null2String(info.get("sendTime_selfsend"));
					if (StringUtils.isNotEmpty(createTime)) {
						createTime = DateUtils.formatDate(DateUtils.parseDate(createTime, "yyyy-MM-dd HH:mm:ss"), showDateFormat);
					}
					info.put("createTime", createTime);
					info.put("processInstanceId", info.get("process_instance_id"));
					info.put("title", info.get("send_title"));
					info.put("startUserGroupName", info.get("starFlowtUnit"));
					info.put("startUserName", info.get("starFlowtUser"));
					//info.put("curStepName", info.get("status_selfsend"));
					info.put("formKey", info.get("form_id"));
					info.put("businessKey", info.get("business_id"));
					info.put("category", info.get("source_category"));
					info.put("item_id", info.get("id"));
					info.put("id", info.get("task_id"));
				}else if("6".equals(module)) {
					createTime = StringUtils.null2String(info.get("attentionTime"));
					if (StringUtils.isNotEmpty(createTime)) {
						if(createTime.length() == 10) {
							createTime = createTime + " 00:00:00";
						}
						Date parseDate = DateUtils.parseDate(createTime, "yyyy-MM-dd HH:mm:ss");
						createTime = DateUtils.formatDate(parseDate, showDateFormat);
					}
					// 标题
	    		  /* String tempTitle = myAttentionService.getProcessSetTitle(info.get("followProcessId").toString());
	    		   if(StringUtils.isNoneEmpty(tempTitle)) {
	    			   info.put("title",tempTitle);
	    		   }*/
					info.put("title",info.get("title"));
					info.put("createTime", createTime);
					info.put("startUserGroupName", info.get("startUnit"));
					info.put("startUserName", info.get("dealUser"));
					info.put("curStepName", info.get("dealStatus"));
					info.put("category", info.get("tableName"));
					info.put("formKey", info.get("form_key_"));
					info.put("processInstanceId", info.get("followProcessId"));
					info.put("businessKey", info.get("tableId"));
					info.put("id", info.get("id_"));
				}else if("7".equals(module)) {
					createTime = StringUtils.null2String(info.get("backTime"));
					if (StringUtils.isNotEmpty(createTime)) {
						createTime = DateUtils.formatDate(DateUtils.parseDate(createTime, "yyyy-MM-dd HH:mm"), showDateFormat);
					}
					info.put("createTime", createTime);
					info.put("processInstanceId", info.get("process_instance_id"));
					info.put("startUserGroupName", info.get("ext_startusergroupname"));
					info.put("startUserName", info.get("ext_startusername"));
					info.put("curStepName", info.get("dealstatus"));
					info.put("id", info.get("task_id"));
				}
				if(!"1".equals(module) && !"3".equals(module) && !"5".equals(module)) {
					Map paramMap2 = new HashMap();
					paramMap2.put("userId", user.getUserId());
					paramMap2.put("corpId", user.getCorpId());
					paramMap2.put("processInstanceId", info.get("processInstanceId"));
					//查询当前环节办理人，上一环节办理人
					if("0".equals(module)) {//待办列表
						if(showItemSet.contains("currentName")) {
							paramMap2.put("taskId", info.get("id"));
							String json = bpmApiService.getProcessList(paramMap2,user.getJwtToken());
							Map m = JsonUtils.readValue(json);
							Map data2 = (Map) m.get("data");
							String currentName = data2.get("undoUsers")+"";
							if(StringUtils.isNotEmpty(currentName)) {
								info.put("currentName", currentName);
							}
						}
						if(showItemSet.contains("preStatus") || showItemSet.contains("preName")) {
							String json2 = bpmApiService.getProcessTrackInfo(paramMap2,"",user.getJwtToken());
							Map m2 = JsonUtils.readValue(json2);
							Map data3 = (Map) m2.get("data");
							List<Map> mapList = (List<Map>)data3.get("activityList");
							// 获取上环节办理状态和办理人
							if(mapList != null && mapList.size() > 0) {
								//Map map2 = mapList.get(mapList.size() -1);
								// 移除掉endTime为空的数据
								Iterator<Map> it = mapList.iterator();
								while(it.hasNext()){
									Map x = it.next();
									String endTime = x.get("endTime")+"";
									if(StringUtils.isEmpty(endTime) || "null".equals(endTime)){
										it.remove();
									}
								}
								// 取endTime时间最大的一个
								Collections.sort(mapList, new Comparator<Map>() {
									@Override
									public int compare(Map o1, Map o2) {
										String endTime1 = o1.get("endTime")+"";
										String endTime2 = o2.get("endTime")+"";
										if (endTime1.compareTo(endTime2)>0) {
											return -1;
										}else {
											return 1;
										}
									}
								});
								if(mapList.size() > 0) {
									Map map2 = mapList.get(0);
									String preName = "";
									List<Map> assigneeList =(List<Map>) map2.get("assigneeList");
									if(assigneeList.size() > 0) {
										for (Map map3 : assigneeList) {
											String assigneeName = "$" + map3.get("name") + "$";
											if(!preName.contains(assigneeName)) {
												preName += assigneeName+",";
											}
										}
										if(preName.length() > 0) {
											preName = preName.substring(0, preName.length() -1);
											preName = preName.replaceAll("\\$", "");
										}
									}
									info.put("preStatus", map2.get("activityName")+"");
									info.put("preName", preName);
								}
							}
						}
					}else {
						if(showItemSet.contains("currentName") || showItemSet.contains("preStatus") || showItemSet.contains("preName")) {
							String json = bpmApiService.getProcessTrackInfo(paramMap2,"",user.getJwtToken());
							Map m = JsonUtils.readValue(json);
							Map data2 = (Map) m.get("data");
							if (data2 != null){
								List<Map> mapList = (List<Map>)data2.get("activityList");
								// 获取当前办理人
								if(mapList != null && mapList.size() > 0) {
									Map map2 = mapList.get(mapList.size() -1);
									String currentName = "";
									List<Map> assigneeList =(List<Map>) map2.get("assigneeList");
									if(assigneeList.size() > 0) {
										for (Map map3 : assigneeList) {
											String assigneeName = "$" + map3.get("name") + "$";
											if(!currentName.contains(assigneeName)) {
												currentName += assigneeName+",";
											}
										}
										if(currentName.length() > 0) {
											currentName = currentName.substring(0, currentName.length() -1);
											currentName = currentName.replaceAll("\\$", "");
										}
									}
									info.put("currentName", currentName);
								}
								if("2".equals(module)) {
									info.put("currentName", info.get("curUserName"));
								}else {
									// 获取上环节办理状态和办理人
									// 移除掉endTime为空的数据
									Iterator<Map> it = mapList.iterator();
									while(it.hasNext()){
										Map x = it.next();
										String endTime = x.get("endTime")+"";
										if(StringUtils.isEmpty(endTime) || "null".equals(endTime)){
											it.remove();
										}
									}
									// 取endTime时间最大的一个
									Collections.sort(mapList, new Comparator<Map>() {
										@Override
										public int compare(Map o1, Map o2) {
											String endTime1 = o1.get("endTime")+"";
											String endTime2 = o2.get("endTime")+"";
											if (endTime1.compareTo(endTime2)>0) {
												return -1;
											}else {
												return 1;
											}
										}
									});
									if(mapList.size() > 0) {
										Map map2 = mapList.get(0);
										String preName = "";
										List<Map> assigneeList =(List<Map>) map2.get("assigneeList");
										if(assigneeList.size() > 0) {
											for (Map map3 : assigneeList) {
												String assigneeName = "$" + map3.get("name") + "$";
												if(!preName.contains(assigneeName)) {
													preName += assigneeName+",";
												}
											}
											if(preName.length() > 0) {
												preName = preName.substring(0, preName.length() -1);
												preName = preName.replaceAll("\\$", "");
											}
										}
										info.put("preStatus", map2.get("activityName")+"");
										info.put("preName", preName);
									}
								}
							}
						}
					}
				}
			}
			map.put("listInfo", listInfo);
		}
		Long enda  = System.currentTimeMillis();
		logger.info("xxx:"+module+"---"+(enda-start));
		return map;
	}

	/**
	 * 设置文件灯、个人灯   
	 * @Title: setLightType   
	 * @param info
	 * @author xuwl
	 * @date 2019-12-28 7:43:38 PM 
	 */ 
	@SuppressWarnings("all")
	private void setLightType(Map info,String module) {
		// 文件灯
		String preWarningDate = info.get("preWarningDate")+"";
		String warningDate = info.get("warningDate")+"";
		info.put("fileLight", "normallight");
		if(StringUtils.isNotEmpty(preWarningDate) && compareDate(preWarningDate)) {
			info.put("fileLight", "warnlight");
		}
		if(StringUtils.isNotEmpty(warningDate) && compareDate(warningDate)) {
			info.put("fileLight", "uragelight");
		}
		
		// 个人灯
		String taskPreWarningDate = info.get("taskPreWarningDate")+"";
		String taskWarningDate = info.get("taskWarningDate")+"";
		info.put("personLight", "normallight");
		if(StringUtils.isNotEmpty(taskPreWarningDate) && compareDate(taskPreWarningDate)) {
			info.put("personLight", "warnlight");
		}
		if(StringUtils.isNotEmpty(taskWarningDate) && compareDate(taskWarningDate)) {
			info.put("personLight", "uragelight");
		}
		// 已办处理
		if("2".equals(module)) {
			String dealTime = info.get("dealTime")+"";
			info.put("personLight", "normallight");
			if(StringUtils.isNotEmpty(taskPreWarningDate) && compareDate2(taskPreWarningDate,dealTime)) {
				info.put("personLight", "warnlight");
			}
			if(StringUtils.isNotEmpty(taskWarningDate) && compareDate2(taskWarningDate,dealTime)) {
				info.put("personLight", "uragelight");
			}
		}
	}
	
	private boolean compareDate(String finishStr) {
		if(finishStr.length() < 19) {
			return false;
		}
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 
		try { 
			Date finishDate = format.parse(finishStr); 
			if(finishDate.before(new Date())) {
				return true;
			}
		} catch (Exception e) { 
			e.printStackTrace(); 
		} 
		return false;
	}
	
	private boolean compareDate2(String finishStr,String dealTimeStr) {
		if(finishStr.length() < 19) {
			return false;
		}
		if(dealTimeStr.length() < 19) {
			return false;
		}
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 
		try { 
			Date finishDate = format.parse(finishStr); 
			Date dealTime = format.parse(dealTimeStr); 
			if(finishDate.before(dealTime)) {
				return true;
			}
		} catch (Exception e) { 
			e.printStackTrace(); 
		} 
		return false;
	}
	
	//判断日期是否是今天
    public boolean isToday(String timeStr) {
    	try {
    		Date time = sdf.parse(timeStr);
    		String param = sdf.format(time);//参数时间
    		String now = sdf.format(new Date());//当前时间
    		if (param.equals(now)) {
    			return true;
    		}
		} catch (Exception e) {
			e.printStackTrace();
		}
        return false;
    }
    
    //判断日期是否是昨天
    public boolean isYesterday(String timeStr) {
    	try {
    		Date time = sdf.parse(timeStr);
    		String param = sdf.format(time);//参数时间
    		Calendar calendar = Calendar.getInstance();
            calendar.setTime(new Date());
            calendar.add(Calendar.DAY_OF_MONTH, -1);
            String yesterDay = sdf.format(calendar.getTime());
            if(param.equals(yesterDay)) {
            	return true;
            }
		} catch (Exception e) {
			e.printStackTrace();
		}
        return false;
    }
 
    //判断日期是否是本周
    public boolean isThisWeek(String timeStr) {
        Calendar calendar = Calendar.getInstance();
        // 设置周一至周日为本周
        calendar.setFirstDayOfWeek(Calendar.MONDAY);
        int currentWeek = calendar.get(Calendar.WEEK_OF_YEAR);
        try {
        	Date time = sdf.parse(timeStr);
        	calendar.setTime(time);
		} catch (Exception e) {
			e.printStackTrace();
		}
        int paramWeek = calendar.get(Calendar.WEEK_OF_YEAR);
        if (paramWeek == currentWeek) {
            return true;
        }
        return false;
    }
    
}
